package com.kinon.ogt.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.kinon.ogt.App;

/**
 * 佛祖保佑 永无BUG
 *
 * @author WangZhiYao
 * @date 2018/4/23
 */
public class SPrefsUtils {

    private static final String FILE_NAME = "OGT";
    private static final String TAG_FIRST_RUN = "FIRST_RUN";
    private static final String TAG_TOKEN = "TOKEN";
    private static final String TAG_USERNAME = "USERNAME";
    private static final String TAG_PASSWORD = "PASSWORD";
    private static final String TAG_VERSION = "VERSION";
    private static final String DEFAULT_STRING = "";

    private static SharedPreferences getSPrefs() {
        return App.getInstance().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    }

    public static void writeFirstRun(boolean firstRun) {
        getSPrefs().edit().putBoolean(TAG_FIRST_RUN, firstRun).apply();
    }

    public static boolean readFirstRun() {
        return getSPrefs().getBoolean(TAG_FIRST_RUN, true);
    }

    public static void writeToken(String token) {
        getSPrefs().edit().putString(TAG_TOKEN, token).apply();
    }

    public static String readToken() {
        return getSPrefs().getString(TAG_TOKEN, DEFAULT_STRING);
    }

    public static void writeUsername(String user) {
        getSPrefs().edit().putString(TAG_USERNAME, user).apply();
    }

    public static String readUsername() {
        return getSPrefs().getString(TAG_USERNAME, DEFAULT_STRING);
    }

    public static void writePassword(String password) {
        getSPrefs().edit().putString(TAG_PASSWORD, password).apply();
    }

    public static String readPassword() {
        return getSPrefs().getString(TAG_PASSWORD, DEFAULT_STRING);
    }

    public static void writeVersion(String version) {
        getSPrefs().edit().putString(TAG_VERSION, version).apply();
    }

    public static String readVersion() {
        return getSPrefs().getString(TAG_VERSION, DEFAULT_STRING);
    }

    public static void clear() {
        getSPrefs().edit().clear().apply();
    }
}
